package com.test.activemq.broker;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class BrokerMain {
	public static void main(String[] args) throws Exception {
		
		
//		BrokerService broker = new BrokerService();
//		broker.setUseJmx(true);
//		broker.addConnector("tcp://localhost:61616");
//		broker.start();
		
//		String uri  = "properties:broker.properties";
//		BrokerService broker = BrokerFactory.createBroker(new URI(uri));
//		broker.addConnector("tcp://localhost:61616");
//		broker.start();
		
//		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
//		BrokerService broker = (BrokerService) context.getBean("broker");
//		broker.start();
		
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		JmsTemplate jmsTemplate = (JmsTemplate) context.getBean("jmsTemplate");
		
		jmsTemplate.send(new MessageCreator() {
			
			@Override
			public Message createMessage(Session session) throws JMSException {
				
				TextMessage msg = session.createTextMessage("我的天呢！");
				return msg;
			}
		});
		
		
	}
}
